<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
          <!--   <div class="fieldBox">
                <div class="label">产品名称</div>
                <div class="field">
                    <input name="prdNm" id="prdNm" type="text"  class="ui-textbox"  value="">
                </div>
            </div> -->
              <div class="fieldBox">
                <div class="label">产品类型</div>
                <div class="field">
                  <input name="prdTypCd" id="prdTypCd" type="text" class="ui-textbox"  onchange="initBrCd()" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox" id="src1">
                <div class="label">产品型号</div>
                <div class="field">
                    <input name="prdMdl" id="prdMdl" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" style="display:none" id="src2">
                <div class="label"> 品牌：</div>
	              <div class="field">
	                  <select id="brCdSelect" name="brCdSelect">
	                  	 <option value=" " >请选择</option>
			             <c:forEach items="${brCdSelectList}" var="brCdModel">
			                <option value="${brCdModel.key }">${brCdModel.value }</option>
			             </c:forEach>
                  	  </select>
	        	</div>
            </div>
            <div class="fieldBox" style="display:none" id="src3">
                <div class="label"> 车系：</div>
	              <div class="field">
	                  <select id="carTypSelect" name="carTypSelect">
	                  	 <option value=" " >请选择</option>
			             <%-- <c:forEach items="${carTypSelectList}" var="carTypModel">
			                <option value="${carTypModel.key }">${carTypModel.value }</option>
			             </c:forEach> --%>
                  	  </select>
	        	</div>
            </div>
               <!-- <div class="fieldBox">
                    <div class="label">厂商名称</div>
                    <div class="field">
                        <input type="text" name="mfrNm" id="mfrNm"   class="ui-textbox"  placeholder="请选择"  ltype="autocomplete"/>
                    </div>
                </div>
                <div class="fieldBox col_50">
	                        	<div class="label">产品品牌</span></div>
				                <div class="field">
				                   <input type="text" name="brCd" id="brCd" placeholder="请选择"/>
				                </div>
				            </div>
   -->
           <%--   <div class="fieldBox">
                   <div class="label">审核状态</div>
                             <div class="field">
                               <select name="audStsCd"  id="audStsCd" >
                                <option value="  " selected="selected">--请选择--</option>
                              <c:forEach items="${audStsList}" var="opt">
                               <option value="${opt.key}">${opt.value}</option>
                              </c:forEach>
                             </select>
                             </div>
                   </div> --%>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
              <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
             <span id="detailBtn" class="sq-button sq-button-round" onclick="detailBtn()">确定</span>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	var prjId= '${prjId}';
	$(function () {
	    var searchPrdTypeTree = null;
		initMfrKvList();
		 //初始化查询条件中的下拉树
		initPrdTypeTreeByUser();
		//initPrdTypeTree();
	    prdGrid();
	   $("#searchBar").ligerForm();
	   initBrCd();
	   $("#prdTypCd").on("change",contrlTypCon);
	   $("#brCdSelect").on("change",contrlBrCdCon);
	});
	
	function contrlTypCon(){
		
		var form = new liger.get("searchBar");
		var yesOrNo=searchPrdTypeTree.treeManager.getSelected().data['tCode'];
		if(yesOrNo.substring(0,3)=="007"||yesOrNo.substring(0,3)=="008"){
			$("#src1").hide();
			$("#src2").show();
			$("#src3").show();
			$("#prdMdl").val(" ");
		}else{
			$("#src1").show();
			$("#src2").hide();
			$("#src3").hide();
			form.setData({
				brCdSelect:" ",
				carTypSelect:" "
			 });
		}
	}
	
	function contrlBrCdCon(){
		
		var cg=$(this).val();
		if(cg!=" "&&cg!=""){
			initCarTypSelect(cg);
		}else{
			liger.get("carTypSelect").clearContent();
			var newOptions='<option value=" ">请选择</option>';
			$("#carTypSelect").html($(newOptions));
	        liger.get("carTypSelect").setSelect();
		}
	}
	
	function initCarTypSelect(cg){
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{brCdId:cg},
			url: '<%=path%>/project/prjbscinfo/getCarTypSelectList.do',
			success:function(data){
				
				liger.get("carTypSelect").clearContent();
				var newOptions='<option value=" ">请选择</option>';
				var options=data.result;
				if(options.length>0){
				for(var i=0;i<options.length;i++){
					newOptions+='<option value="'+options[i]+'">'+options[i]+'</option>';
					}
				}
	            $("#carTypSelect").html($(newOptions));
	            liger.get("carTypSelect").setSelect();
				
			},
			error:function(data){
				$.ligerDialog.SQalert({content: "加载车系失败！",SQ_type: "error"});
			}
		});
	}
	function initBrCd(){
	 	//根据选择类型刷新品牌下拉数据
		var sGrpCd = null;
		var sCode = null;
	    if(searchPrdTypeTree.treeManager.getSelected()){
		   	sGrpCd = searchPrdTypeTree.treeManager.getSelected().data['sGrpCd'];//源代码组值
			sCode = searchPrdTypeTree.treeManager.getSelected().data['sCode'];//源代码值
        }
		
	   	$("#brCd").ligerComboBox({
            url: '<%=path%>/product/prdBscInfo/searchBrCdJSON.do',
            ajaxType: "get",
            parms:{mTypCd:'M0002', sGrpCd:sGrpCd, sCode:sCode},
            width: 178,
            valueField: 'key',
    		textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                if (this.findValueByText(value) == "") {//清除输入值
                    liger.get("brCd").setValue("");
                }
            }
        });
	}
	//根据产品类型加载不同的grid
	function prdGrid(prdType,parms){
		var audStsCdList = new Array();
		audStsCdList.push(CommonConstant.C_AUD_NO_HAPPEN_CODE);
		audStsCdList.push(CommonConstant.C_AUD_ADNWAY_CODE);
		audStsCdList.push(CommonConstant.C_AUD_PASS_CODE);
		var audStsCdListArr = JSON.stringify(audStsCdList);
		//alert(JSON.stringify(parms));
		if(prdType){
			var type = prdType.substring(0,ProjectConstant.PRD_TYE_LENGHT);
			if(type==ProjectConstant.PRD_CAR_CD||type==ProjectConstant.PRD_BUS_CD||type==ProjectConstant.PRD_TK_BUS_CD||type==ProjectConstant.PRD_XNY_CAR_CD||type==ProjectConstant.PRD_XNY_BUS_CD){
			    $("#ligergrid1").ligerGrid({
			    	url: '<%=path%>/project/prjbscinfo/initPrdCarList.do?prdTypCd='+prdType+'&&audStsCdList='+audStsCdListArr,
			    	method : 'get',
			    	parms : parms,
			        columns: [
                        { display: '产品名称', name: 'prdNm', minWidth: 150 ,
                    		render: function (rowdata, rowindex, value, column) { 
       	            		 value ==null?"":value;
       	            		var h = '';
       	            		if(rowdata.audStsCd){
       	            		  if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
       		                    	h+='<i class="ico_flasher"></i>';
       		                    }
       	            		}
       	                        h+=value;
       	                        return h;
       	            	},
                        	enabledSort:true},
                        { display: '参考价', name: 'guidePc', width: 100, 
    			             	render: function (rowdata, rowindex, value, column) { 
    			             		if(value){
    			            		var h = value/100;
    			                     return h;
    			             		}
    			            		},
    			            enabledSort:true},
	                    { display: '产品类型', name: 'prdTypCdNm', minWidth: 150 , enabledSort:true},
			            { display: '品牌', name: 'brCd', width: 50 , enabledSort:true},
			            { display: '驱动形式', name: 'drvTypCdNm', minWidth: 100 , enabledSort:true},
			            { display: '发动机型号', name: 'engMdl', minWidth: 140 , enabledSort:true},
			            { display: '产品状态', name: 'audStsCdNm', width: 50, enabledSort:true}
			           /*  { display: '货箱', name: 'cntrSz', minWidth: 140 , enabledSort:true}, */
			            /* { display: '产品名称', name: 'prdNm', minWidth: 140 , enabledSort:true},
			            { display: '厂商', name: 'mfrNm', minWidth: 140 , enabledSort:true},
			            { display: '产品状态', name: 'audStsCdNm', width: 50, enabledSort:true},
			            { display: '产品型号', name: 'prdMdl', minWidth: 140 , enabledSort:true},
			            { display: '车系', name: 'prdSeries', minWidth: 140 , enabledSort:true},
			            { display: '生产年份', name: 'prdYr', minWidth: 140 , enabledSort:true},
			            { display: '国别', name: 'prdCyCdNm', minWidth: 140 , enabledSort:true},
			            { display: '座位', name: 'seatQtyCdNm', minWidth: 140 , enabledSort:true},
			            { display: '车身颜色', name: 'carCl', minWidth: 140 , enabledSort:true}, */
			        ],
			        pageSize:10,
			        root:'rows',
			        record:'total',
			        hideLoadButton : true,
			        width: '100%',
			        height:'100%',
			        heightDiff:-2,
			        //isScroll: false,
			        checkbox:true,
			        rownumbers:true/* ,
			        onRenderComplete: function () {
			        	iframeResize ();
			        } */
			    });
			}else{
			    $("#ligergrid1").ligerGrid({
			    	url: '<%=path%>/project/prjbscinfo/initPrdTkList.do?prdTypCd='+prdType+'&&audStsCdList='+audStsCdListArr,
			    	method : 'get',
			    	parms : parms,
			        columns: [
                        { display: '产品名称', name: 'prdNm', minWidth: 140 ,
                        	render: function (rowdata, rowindex, value, column) { 
          	            		 value ==null?"":value;
          	            		var h = '';
          	            		if(rowdata.audStsCd){
          	            		  if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
          		                    	h+='<i class="ico_flasher"></i>';
          		                    }
          	            		}
          	                        h+=value;
          	                        return h;
          	            	},enabledSort:true},
			            { display: '产品类型', name: 'prdTypCdNm', minWidth: 140 , enabledSort:true},
			            { display: '品牌', name: 'brCd', width: 50 , enabledSort:true},
			            { display: '驱动形式', name: 'drvTyp', minWidth: 140 , enabledSort:true},
			            { display: '发动机型号', name: 'engMdl', minWidth: 140 , enabledSort:true},
			            { display: '货箱', name: 'cntrSz', minWidth: 140 , enabledSort:true},
			            { display: '产品状态', name: 'audStsCdNm', width: 50, enabledSort:true},
			            
			            /* { display: '产品名称', name: 'prdNm', minWidth: 140 , enabledSort:true},
			            { display: '厂商', name: 'mfrNm', minWidth: 140 , enabledSort:true},
			            { display: '产品状态', name: 'audStsCdNm', width: 50, enabledSort:true},
			            { display: '马力', name: 'hp', minWidth: 140 , enabledSort:true},
			            { display: '变速箱型号', name: 'grboxMdl', minWidth: 140 , enabledSort:true},
			            { display: '轮胎规格', name: 'mWhlSpec', minWidth: 140 , enabledSort:true},
			            { display: '板材材质', name: 'matQalCdNm', minWidth: 140 , enabledSort:true},
			            { display: '举升方式', name: 'liftWayCdNm', minWidth: 140 , enabledSort:true}, */
			        ],
			        pageSize:10,
			        root:'rows',
			        record:'total',
			        hideLoadButton : true,
			        width: '100%',
			        height:'100%',
			        heightDiff:-2,
			        //isScroll: false,
			        checkbox:true,
			        rownumbers:true/* ,
			        onRenderComplete: function () {
			        	iframeResize ();
			        } */
			    });
			}
		}else{
			   $("#ligergrid1").ligerGrid({
			    	url: '<%=path%>/project/prjbscinfo/initPrdTkList.do?prdTypCd=""',
			    	method : 'get',
			        columns: [
                          { display: '产品名称', name: 'prdNm', minWidth: 140 , 
                        	  render: function (rowdata, rowindex, value, column) { 
            	            		 value ==null?"":value;
            	            		var h = '';
            	            		if(rowdata.audStsCd){
            	            		  if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
            		                    	h+='<i class="ico_flasher"></i>';
            		                    }
            	            		}
            	                        h+=value;
            	                        return h;
            	            	},
                        	  enabledSort:true},
			              { display: '产品类型', name: 'prdTypCdNm', minWidth: 140 , enabledSort:true},     
			              { display: '品牌', name: 'brCd', width: 50 , enabledSort:true},
			              { display: '驱动形式', name: 'drvTyp', minWidth: 140 , enabledSort:true},
			              { display: '发动机型号', name: 'engMdl', minWidth: 140 , enabledSort:true},
			              { display: '货箱', name: 'cntrSz', minWidth: 140 , enabledSort:true},
			              { display: '产品状态', name: 'audStsCdNm', width: 50, enabledSort:true},
			              
			          /*   { display: '产品名称', name: 'prdNm', minWidth: 140 , enabledSort:true},
			            { display: '厂商', name: 'mfrNm', minWidth: 140 , enabledSort:true},
			            { display: '产品状态', name: 'audStsCdNm', width: 50, enabledSort:true},
			            { display: '马力', name: 'hp', minWidth: 140 , enabledSort:true},
			            { display: '变速箱型号', name: 'grboxMdl', minWidth: 140 , enabledSort:true},
			            { display: '轮胎规格', name: 'mWhlSpec', minWidth: 140 , enabledSort:true},
			            { display: '货箱', name: 'cntrSz', minWidth: 140 , enabledSort:true},
			            { display: '板材材质', name: 'matQalCdNm', minWidth: 140 , enabledSort:true},
			            { display: '举升方式', name: 'liftWayCdNm', minWidth: 140 , enabledSort:true}, */
			        ],
			        pageSize:10,
			        root:'rows',
			        record:'total',
			        hideLoadButton : true,
			        width: '100%',
			        height:'100%',
			        heightDiff:-2,
			        //isScroll: false,
			        checkbox:true,
			        rownumbers:true/* ,
			        onRenderComplete: function () {
			        	iframeResize ();
			        } */
			    });
		}
		grid = liger.get("ligergrid1");
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function searchBtn(){
		         var form = new liger.get("searchBar");
		 		if(null==searchPrdTypeTree.treeManager.getSelected()||searchPrdTypeTree.treeManager.getSelected()==""){
		 			$.ligerDialog.SQalert({content: "请选择一个产品类型", SQ_type: "warring"});
		 			return;
		 		}
		         var data = form.getData();
		         var parms = {};
		         for (name in data){
		            //grid.setParm(name,data[name]);
		            parms[name] = data[name];
		         };
		         if(searchPrdTypeTree.treeManager.getSelected()){
		        	 var prdCd = searchPrdTypeTree.treeManager.getSelected().data['tCode'];
		 	         if(prdCd){
		 	        	 data["prdTypCd"] = prdCd;
		 	         }
		         }
		         prdType = searchPrdTypeTree.treeManager.getSelected().data['tCode'];
		         prdGrid(prdType,parms);
	}
	
	function detailBtn(){
		var prdCd = null;
		var bizTypCd = null;
		var bizCd = null;
		var sGrpCd = null;
		var sCode = null;
		var prdTypCdNm = null
		
	    if(searchPrdTypeTree.treeManager.getSelected()){
	     //  	prdCd = searchPrdTypeTree.treeManager.getSelected().data['id'];
		   	bizTypCd = searchPrdTypeTree.treeManager.getSelected().data['tGrpCd'];//目标代码组值
		   	bizCd = searchPrdTypeTree.treeManager.getSelected().data['tCode'];//目标代码值
		   	sGrpCd = searchPrdTypeTree.treeManager.getSelected().data['sGrpCd'];//源代码组值
			sCode = searchPrdTypeTree.treeManager.getSelected().data['sCode'];//源代码值
		   	prdTypCdNm =searchPrdTypeTree.treeManager.getSelected().data['tName'];//目标代码名
        }
		
		//alert(bizTypCd+"---"+bizCd+"---"+sGrpCd+"---"+sCode+"---"+prdTypCdNm);
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}

		
		var callback = frameElement.dialog.get("callback");
		var id = selectedRows[0].id;
		var prdTypCd= selectedRows[0].prdTypCd;
		var prdCd = selectedRows[0].prdBscInfoVO.prdCd;
		parent.Add_navTab('tab_project_prd_detail'+id,'项目产品详细信息','<%=path%>/project/prjbscinfo/toPrjPrdDetailPage.do?id='+id+'&&prdCd='+prdCd+'&&prdTypCd='+prdTypCd+'&&bizTypCd='+bizTypCd+'&&bizCd='+bizCd+'&&sGrpCd='+sGrpCd+'&&sCode='+sCode+'&&prdTypCdNm='+prdTypCdNm+'&&prjId='+prjId,callback);
		parent.$.ligerDialog.close();
		parent.$(".l-dialog,.l-window-mask").css("display","none"); 
	}
	
	function clearBtn(){
		var form = new liger.get("searchBar");
		//form.clear();
		form.setData({
			prdMdl:" ",
			brCdSelect:" ",
			carTypSelect:" "
		/* 	prdNm:" ",
			prdMdl:" ",
			mfrNm:" ",
			brCd:" " */
		 });
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	
	function initPrdTypeTreeByUser(){
		searchPrdTypeTree = $("#prdTypCd").ligerComboBox({
            // width: 178,
            selectBoxWidth: 240,
            selectBoxHeight: 150,
            treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
            textField:"tName",
            valueField:"tCode",
            tree: {
                url: '<%=path%>/product/prdBscInfo/getPrdTyeDataForSearch.do',
                ajaxType: 'get',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                textFieldName:"tName",
                idFieldName:"tCode",
                onSuccess: function () {
                    var treeselect=liger.get("prdTypCd");
                    //treeselect.setValue("Q");
                }
            }
        });
	}
	
    function initPrdTypeTree(){
    	searchPrdTypeTree = $("#prdTypCd").ligerComboBox({
    		width:178,
             selectBoxWidth: 240,
             selectBoxHeight: 150,
             treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
             tree: {
                 ajaxType: 'get',
                 textFieldName:"text",
                 idFieldName:"id",
                 checkbox: false,
                 parentIcon: "none",
                 childIcon: "none"
             }
         });
    	 $.ajax({
     		type: 'get',
     		dataType:'json',
     		data: "",
     		url: '<%=path%>/project/prjbscinfo/getPrdTyeData.do',
     		success:function(msg){
     			if(msg){
     				firstNode = msg.data[0].id;
     				searchPrdTypeTree.treeManager.setData(msg.data);
     				searchPrdTypeTree.clear();
     				 /*   if(!searchPrdTypeTree.treeManager.getSelected()){
     					  //没有选中，默认第一个节点的一个孩子节点
     					 searchPrdTypeTree.selectValue(firstNode);  
     				    prdGrid(firstNode);
     				   	grid = liger.get("ligergrid1");
     				    grid.setHeight(100);
     				    $("#pageloading").hide();
     				  }  */
     			}else{
     				 $.ligerDialog.SQalert({content: "加载产品分类失败！",SQ_type: "error"});
     			}
     		}
     	});
    	 
    }

	function initMfrKvList(){
		var _url = '<%=path%>/project/prjbscinfo/getMfrKvlist.do';
		 var mfrSelect =  $("#mfrNm").ligerComboBox({
				 url:_url, 
	          ajaxType: "get",
	           autocomplete: function (e){
	                filter_autoComboboxData(e.key, this);
	                e.show();
	            }, 
	          width: 178,
	          valueField: 'id',
              textField: 'text',
	          keySupport:true,
	          onChangeValue :function(value){
	          }
	      });
		}
</script>

</body>
</html>